.
<template>
  <div>
    <tableComponents
      :pagination="{ currentPage, pageSize, total: list.all_num }"
      :isHaveExport="false"
      :isHaveAdd="$store.state.manageInfo.role_con == 'god'"
      addText="充值金额"
      @toAdd="add_data"
      @handleCurrentChange="handleCurrentChange"
      @handleSizeChange="handleSizeChange"
      :searchData="userSearchData"
      @sendUserSearch="receive_search"
    >
      <template v-slot:table>
        <el-table
          ref="multipleTable"
          :data="list.data"
          stripe
          v-loading="loading"
          header-row-class-name="head_color"
          tooltip-effect="dark"
          style="width: 99.8%"
          @selection-change="handleSelectionChange"
        >
          <el-table-column label="充值信息" min-width="160">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>流量大小：</span>
                  <span>{{ Number(scope.row.flow) }}M</span>
                </div>
                <div>
                  <span>充值金额：</span>
                  <span>{{ Number(scope.row.money) }}</span>
                </div>
                <div>
                  <span>备注：</span>
                  <span>{{ scope.row.remark }}</span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="使用详情" min-width="160">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>已使用流量：</span>
                  <span>{{ Number(scope.row.used) }}M</span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="使用状态" min-width="160">
            <template slot-scope="scope">
              <el-tag style="color: #fff" type="success" effect="dark" v-if="scope.row.status == 0">使用中</el-tag>
              <el-tag style="color: #fff" type="danger" effect="dark" v-else-if="scope.row.status == 1">已用完</el-tag>
              <el-tag style="color: #fff" type="" effect="dark" v-else-if="scope.row.status == 2">已到期</el-tag>
            </template>
          </el-table-column>
          <el-table-column label="时间信息" min-width="220">
            <template slot-scope="scope">
              <div class="tab_div">
                <div>
                  <span>充值时间：</span>
                  <span>{{ scope.row.created_time | getTimeFormat }}</span>
                </div>
                <div>
                  <span>更新时间：</span>
                  <span>{{ scope.row.update_time | getTimeFormat }}</span>
                </div>
                <div>
                  <span>到期时间：</span>
                  <span>{{ scope.row.end_time | getTimeFormat }}</span>
                </div>
              </div>
            </template>
          </el-table-column>
          <el-table-column label="操作" min-width="120">
            <template slot-scope="scope">
              <el-row class="myblank">
                <el-button :loading="$store.state.isLoading" size="mini" @click="usebtn(scope.row)" type="primary">使用记录</el-button>
                <!-- <el-button :loading="$store.state.isLoading" size="mini" @click="editbtn(scope.row)" type="primary">编辑</el-button> -->
                <!-- <el-button :loading="$store.state.isLoading" size="mini" type="danger" @click="deletebtn(scope.row.id)">删除</el-button> -->
              </el-row>
            </template>
          </el-table-column>
        </el-table>
      </template>
    </tableComponents>

    <el-dialog :close-on-click-modal="false" title="充值金额" class="tl size_13" width="1200px" :visible.sync="dialogFormVisible">
      <el-form :model="edit_form" ref="form" label-width="170px">
        <el-form-item label="充值流量：">
          <el-col :span="6">
            <el-input type="text" :rows="6" clearable placeholder="请输入流量" v-model="edit_form.flow_t" autocomplete="off">
              <span slot="append">T</span>
            </el-input>
          </el-col>
          <el-col :span="6">
            <el-input type="text" :rows="6" clearable placeholder="请输入流量" v-model="edit_form.flow_g" autocomplete="off">
              <span slot="append">G</span>
            </el-input>
          </el-col>
          <el-col :span="6">
            <el-input type="text" :rows="6" clearable placeholder="请输入流量" v-model="edit_form.flow_m" autocomplete="off">
              <span slot="append">MB</span>
            </el-input>
          </el-col>
          <el-col> 总充值流量：{{ sum_flow }}M </el-col>
        </el-form-item>

        <el-form-item label="充值金额：">
          <el-col :span="12">
            <el-input type="text" :rows="6" clearable placeholder="请输入充值金额" v-model="edit_form.money" autocomplete="off"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item label="到期时间：">
          <el-col :span="12">
            <el-date-picker v-model="edit_form.end_time_cn" type="datetime" value-format="timestamp" placeholder="选择日期"></el-date-picker>
          </el-col>
        </el-form-item>
        <el-form-item label="备注：">
          <el-col :span="12">
            <el-input type="text" :rows="6" clearable placeholder="请输入备注" v-model="edit_form.remark" autocomplete="off"></el-input>
          </el-col>
        </el-form-item>
        <el-form-item>
          <el-button :loading="$store.state.isLoading" type="primary" @click="editlive(edit_form)">编 辑</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>

    <el-dialog :close-on-click-modal="false" title="使用记录" :visible.sync="dialogUseRecordVisible" class="tl size_13" width="1500px">
      <tableComponents
        :pagination="{ currentPage2, pageSize2, total: userecordList.all_num }"
        @handleCurrentChange="handleCurrentChange2"
        @handleSizeChange="handleSizeChange2"
        :searchData="userSearchData2"
        @sendUserSearch="receive_search2"
        :isHaveAdd="false"
        :isHaveExport="false"
        :HeadShow="false"
      >
        <template v-slot:table>
          <el-table ref="multipleTable" :data="userecordList.data" stripe v-loading="loading" header-row-class-name="head_color" tooltip-effect="dark" style="width: 99.8%">
            <el-table-column label="头像" min-width="50">
              <template slot-scope="scope">
                <div class="img_bor_tx">
                  <img :src="$fnc.getImgUrl(scope.row.avatar)" alt />
                </div>
              </template>
            </el-table-column>
            <el-table-column label="用户信息" min-width="120">
              <template slot-scope="scope">
                <div class="tab_div">
                  <div>
                    <span>用户昵称：</span>
                    <span>{{ scope.row.nickname || "----" }}</span>
                  </div>
                  <div>
                    <span>用户名：</span>
                    <span>{{ scope.row.username || "----" }}</span>
                  </div>
                </div>
              </template>
            </el-table-column>

            <el-table-column label="使用流量" min-width="160">
              <template slot-scope="scope"> {{ Number(scope.row.flow) }}m </template>
            </el-table-column>
            <!-- <el-table-column label="视频信息" min-width="160">
              <template slot-scope="scope">
                <div class="tab_div">
                  <div>
                    <span>视频地址：</span>
                    <span>{{ scope.row.video }}</span>
                  </div>
                  <div>
                    <span>视频大小：</span>
                    <span>{{ Number(scope.row.size) }}M</span>
                  </div>
                </div>
              </template>
            </el-table-column> -->
            <el-table-column label="添加时间" min-width="160">
              <template slot-scope="scope">{{ scope.row.created_time | getTimeFormat }}</template>
            </el-table-column>
            <!-- <el-table-column label="结束使用时间" min-width="160">
              <template slot-scope="scope">{{ scope.row.end_time | getTimeFormat }}</template>
            </el-table-column> -->
          </el-table>
        </template>
      </tableComponents>
    </el-dialog>
  </div>
</template>
<script>
import { videoUseRecordSearchData } from "../../assets/js/searchData/searchData"; //引入搜索的数据

export default {
  data() {
    return {
      useid: {},
      currentPage2: 1,
      pageSize2: 10,
      userecordList: {},
      dialogUseRecordVisible: false,
      userSearchData: videoUseRecordSearchData,
      userSearchData2: videoUseRecordSearchData,

      end_time: "",
      current: "xz_driverwork",
      shows: false,
      is_edit: false,
      dialogFormVisible: false,
      edit_form: {},
      loading: false,
      list: [],
      allPage: 0,
      allNum: 0,
      pageSize: 10,
      currentPage: 1,
      searchAll: {},
      row: {},
      multipleSelection: [],
      showCity: true,
    };
  },
  computed: {
    sum_flow() {
      var t = Number(this.edit_form.flow_t || 0);
      var g = Number(this.edit_form.flow_g || 0);
      var m = Number(this.edit_form.flow_m || 0);
      return t * 1048576 + g * 1024 + m;
    },
  },
  components: {},
  methods: {
    receive_search2(obj) {
      this.searchAll2 = obj;
      this.getNewsAll2(obj);
    },
    handleSizeChange2(val) {
      console.log(val);
      var params = {};
      this.currentPage2 = 1;
      this.pageSize2 = val;
      params.page = "";
      params.page_size = this.pageSize2;
      this.getNewsAll2(params);
    },
    handleCurrentChange2(val) {
      this.currentPage2 = val;
      var params = this.searchAll2;
      params.page = this.currentPage2;
      params.page_size = this.pageSize2;
      this.getNewsAll2(params);
    },
    getNewsAll2(data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      params.fid = this.useid;
      this.$api.getPage.get_video_userecord(params).then((res) => {
        if (res.data.code == 200) {
          this.userecordList = res.data.result;
          this.dialogUseRecordVisible = true;
        }
        this.loading = false;
      });
    },
    usebtn(item) {
      this.useid = item.id;
      this.currentPage2 = 1;
      this.getNewsAll2();
    },
    getShow(val) {
      this.shows = val;
    },
    getSend(row) {
      this.edit_form.username = row.username;
      this.edit_form.uid = row.uid;
    },
    xzshop() {
      this.shows = true;
    },
    sorta(a, b) {
      return b - a;
    },
    sortNew(index, row) {
      var params = {};
      params = row;
      params.id = row.id;
      params.sort = row.sort;
      this.$api.getPage.edit_video_traffic(params).then((res) => {
        if (res.data.code == 200 && res.data.result) {
          return;
        } else {
          this.$fnc.alertError(res.data.code_desc, res.data.result); //失败弹出框
        }
      });
    },
    handleSelectionChange(val) {
      this.multipleSelection = val;
    },
    deleteAll() {
      //批量删除
      var str = "";
      if (this.multipleSelection.length <= 0) {
        this.$message.error("未选择批量删除");
      } else {
        for (var i in this.multipleSelection) {
          str += this.multipleSelection[i].id + "@";
        }
        str = str.slice(0, -1);
        this.$swal({
          title: "您确定要删除这些信息吗",
          text: "删除后将无法恢复，请谨慎操作！",
          type: "warning",
          showCancelButton: true,
          confirmButtonColor: "#DD6B55",
          confirmButtonText: "是的，我要删除",
          cancelButtonText: "容我三思",
        }).then((willDelete) => {
          if (willDelete.value) {
          }
        });
      }
    },
    deletebtn(id) {
      //删除
      this.$swal({
        title: "您确定要删除这些信息吗",
        text: "删除后将无法恢复，请谨慎操作！",
        type: "warning",
        showCancelButton: true,
        confirmButtonColor: "#DD6B55",
        confirmButtonText: "是的，我要删除",
        cancelButtonText: "容我三思",
      }).then((willDelete) => {
        if (willDelete.value) {
        }
      });
    },
    add_data() {
      this.is_edit = false;
      var date = new Date();
      date.setFullYear(date.getFullYear() + 1); //加一年
      this.edit_form = {
        flow: "",
        flow_t: "",
        flow_g: "",
        flow_m: "",
        money: "",
        end_time_cn: date,
      };
      this.dialogFormVisible = true;
    },
    onSuccess(pic) {
      this.edit_form.piclink = pic;
    },
    getIs(val, row) {
      this.is_edit = true;
      var params = {};
      params = row;
      params.id = row.id;
      params.show = val;
      this.editlive(params);
    },

    editlive(item) {
      var params = {};
      if (this.is_edit == false) {
        params.flow = this.sum_flow;
        params.money = this.edit_form.money;
        params.end_time = parseInt(Number(this.edit_form.end_time_cn) / 1000);
        params.remark = this.edit_form.remark;
        this.$api.getPage.add_video_traffic(params).then((res) => {
          if (res.data.code == 200) {
            this.dialogFormVisible = false;
            this.$fnc.alertSuccess(res.data.result);
            this.getNewsAll(this.searchAll);
          } else {
            this.$fnc.alertError(res.data.result);
          }
        });
      } else {
      }
    },
    editbtn(item) {
      this.is_edit = true;
      this.edit_form = JSON.parse(JSON.stringify(item));

      this.dialogFormVisible = true;
    },

    receive_search(obj) {
      this.searchAll = obj;
      this.getNewsAll(obj);
    },
    getNewsAll(data) {
      this.loading = true;
      var params = {};
      data = data || {};
      params = data;
      this.$api.getPage.get_video_traffic(params).then((res) => {
        if (res.data.code == 200) {
          this.list = res.data.result;
        }
        this.loading = false;
      });
    },
    handleSizeChange(val) {
      var params = this.searchAll;
      params.page = "";
      params.page_size = val;
      this.getNewsAll(params);
      this.pageSize = val;
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      var params = this.searchAll;
      params.page = val;
      params.page_size = this.pageSize;
      this.getNewsAll(params);
    },

    reload() {
      this.getNewsAll(this.searchAll);
    },
  },
  beforeCreate() {},
  created() {
    this.getNewsAll();
  },
};
</script>

<style lang="less" scoped>
.myblank button {
  margin: 5px 5px 0 0;
}
</style>
